﻿using Abp.Web.Models;
using Microsoft.AspNetCore.Mvc.ModelBinding;

namespace Batman.Cms.Core.Models.Mvc
{
    public class ResponseBase : AjaxResponse
    {
        public ResponseBase(bool success = true) : base()
        {
            this.Success = success;
        }

        public ResponseBase(bool success, string error) : base()
        {
            this.Success = success;
            this.Error = new ErrorInfo(error);
        }

        /// <summary>
        /// 错误返回
        /// </summary>
        /// <param name="code"></param>
        /// <param name="error"></param>
        /// <param name="success"></param>
        public ResponseBase(int code, string error, bool success = false) : base()
        {
            this.Success = success;
            this.Error = new ErrorInfo(code, error);
        }

        public void AddModelError(ModelStateDictionary ModelState)
        {
            ModelState.AddModelError(string.Empty, this.Error.Message);
        }
    }

    public class ResponseBase<T> : AjaxResponse<T>
    {
        public ResponseBase(T result) : base(true)
        {

        }

        public ResponseBase(bool success = true) : base(success)
        {

        }

        public ResponseBase(bool success, string error) : base()
        {
            this.Success = success;
            this.Error = new ErrorInfo(error);
        }

        public void AddModelError(ModelStateDictionary ModelState)
        {
            ModelState.AddModelError(string.Empty, this.Error.Message);
        }
    }
}
